package com.example.sociamedia.post.mapper;

import com.example.sociamedia.post.entity.Comment;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface CommentMapper {
    @Insert("INSERT INTO comments (PostId, UserId, Content, CreatedAt, UpdatedAt, ParentId) VALUES (#{postId}, #{userId}, #{content}, NOW(), NOW(), #{parentId})")
    @Options(useGeneratedKeys = true, keyProperty = "commentId", keyColumn = "CommentId")
    int insertComment(Comment comment);

    @Select("SELECT * FROM comments WHERE PostId = #{postId} ORDER BY CreatedAt ASC")
    List<Comment> selectCommentsByPost(@Param("postId") Long postId);

    @Delete("DELETE FROM comments WHERE CommentId = #{commentId} AND UserId = #{userId}")
    int deleteComment(@Param("commentId") Long commentId, @Param("userId") Long userId);
} 